﻿using System;
using System.Web;
using System.Web.Routing;
using SC2ProArena.Domain.Model.Games;

namespace SC2ProArena.Interfaces.WebSite.Navigation.RouteConstraints
{
	public class RaceConstraint : IRouteConstraint
	{
		static string[] _races = new string[] {
			"protoss", "zerg", "terran", "random"
		};

		public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
		{
			var val = values["race"];
			if (val == null)
				return true;

			var requestedString = val.ToString();
			foreach (var item in _races)
			{
				if (string.Compare(requestedString, item, StringComparison.InvariantCultureIgnoreCase) == 0)
					return true;
			}

			return false;
		}
	}
}